require 'semantictext/ftptag.rb'
require 'semantictext/httptag.rb'
require 'semantictext/mailtotag.rb'
require 'semantictext/unknown_tag'

module SemanticText
  # I create SemanticText::Tag objects in response to create_tag(name,value) calls 
  # from a SemanticText::Document
  class DefaultTagFactory

    def initialize()
      @taglookup = {}
      @taglookup['http']=HTTPTag
      @taglookup['ftp']=FTPTag
      @taglookup['mailto']=MailToTag
    end
    
    def create_tag(name, value)
      target = @taglookup[name]
      if target.nil?
        throw UnknownTag.new("#{name}:#{value}")
      end
      target.new(name,value)
    end

    def register_tag(name, tagclass)
      throw ArgumentError.new("must register a tag class with a String key, but was #{name.class}") unless name.class.equal? String 
      @taglookup[name]=tagclass
    end
  end
end
